import UtilFuncs from "../../common/tools/utilfuncs"
var funcs = UtilFuncs.UtilFuncs;

import globalConst from "../../common/globalConst";
var global = globalConst.GlobalConst;

import pathcopysvc from "./pathcopysvc";

var BufToGraphSvc = {}

BufToGraphSvc.copyProp = function (buf, graph,offsetx,offsety) {
    if (funcs.isBaseUnit(buf.type)) {
        this.copyBaseGraphProp(buf, graph);
    }
    else if (funcs.isText(buf.type)) {
        this.copyTextGraphProp(buf, graph);
    }
    else if (funcs.mainObjType(buf.type) == global.PathType){
        pathcopysvc.PathGraphCopySvc.copyPathProp(buf,graph,offsetx,offsety);
    }
}

BufToGraphSvc.copyBaseGraphProp = function (info, graph) {
    let lineDef = graph.getLineDef();
    lineDef.color.setColorByValue(info.color);
    lineDef.linemode = info.lineMode;
    lineDef.joinmode = info.lineJoin;
    lineDef.capmode = info.lineCap;
    lineDef.lineWidth = info.lineWidth;

    let fillDef = graph.getFillDef();
    fillDef.clone(info.fillInfo);
}

BufToGraphSvc.copyTextGraphProp = function (info, graph) {
    graph.m_orignalText = info.sOrigContent;
    graph.m_formatText = info.sFormatContent;
    graph.m_fontInfo.fontsize = info.fontsize;
    graph.m_fontInfo.linespace = info.linespace;        // 行间距
    graph.m_fontInfo.fontFamily = info.fontFamily;
    graph.m_fontInfo.bold = info.bold;			  // 粗体
    graph.m_fontInfo.italic = info.italic;		  // 倾斜
    graph.m_fontInfo.underline = info.underline;	  // 带下划线
    graph.m_fontInfo.strikeout = info.strikeout;	  // 中间有直线通过的文
    graph.m_fontInfo.alignType = info.alignType;
    graph.m_fontInfo.fontColor.setColorByValue(info.color);
    graph.m_fontInfo.fontBKColor.setColorByValue(info.backColor);
    graph.m_fontInfo.useBKFlag = info.useBKFlag;
}
export default { BufToGraphSvc }